<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta name="renderer" content="webkit|ie-comp|ie-stand" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>学生-班级-资源</title>
<%@ include file="/common/commonLib.jsp"%>
<link rel="stylesheet" href="<c:url value='/css/courseResourceStuIndex.css'/>" type="text/css"/>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/common-main.css'/>"/>
<script src="<c:url value='/js/courseResourceStuIndex.js'/>" type="text/javascript" charset="utf-8"></script>
</head>
<body>	
	<%@include file="/common/header.jsp"%>
	<%@include file="classHeader.jsp"%>
	<div class="container-fluid main">
		<div class="row">
			<div class="col-xs-12 col-sm-12 col-md-9">
				<div class="row">
					<div class="col-md-12">
						<%@include file="classNav.jsp"%>
						<div class="row" id="resource-list">
							<div class="course-resource-stu">
								<!--资源列表 -->
								<div class="col-md-12 col-xs-12">
									<table class="table table-hover">
										<thead>
											<tr>
												<th>资源名</th>
												<th class="show-pc">上传者</th>
												<th class="show-pc">上传时间</th>
												<th>下载</th>
											</tr>
										</thead>
										<tbody id="resourceList">
											
										</tbody>
									</table>
								</div>
							</div>
							<div class="row">
								<!-- 分页 -->
								<div class="page-content" id="resourcePage">
									<nav class="pagination" role="navigation">
										<a class="last-page" href="#">
											<i class="fa fa-angle-left"></i>
										</a>
										<span class="page-number">第1页/共7页</span>
										<a class="next-page" href="#">
											<i class="fa fa-angle-right"></i>
										</a>
									</nav>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			
			<!--教师、助教信息，课程简介-->
			<div class="col-xs-12 col-md-3">
				<%@include file="classRight.jsp"%>
			</div>
		</div>		
	</div>
	<%@include file="/common/footer.jsp"%>
</body>
<script>
var data=${data};
$(document).ready(function() {
	if (data.status != "success") {
		alert(data.message);
		return;
	};
	$("#resource").css("color","#00b43c");
	initClassView(data.data.classView);
	initTable(data.data);
 });
 
 var initTable = function(data){
	 var resourceList =$("#resourceList");
	 resourceList.empty();
	 for(var i=0;i<data.list.length;i++){
		 var item=data.list[i];
		 var s="<tr>";
		 	s+="<td title=\""+item.fileName+"\">"+item.fileName+"</td>";
			s+="<td class=\"show-pc\" title=\""+item.uploaderName+"\">"+item.uploaderName+"</td>";
			s+="<td class=\"show-pc\" title=\""+item.uploadTime+"\">"+item.uploadTime+"</td>";
			s+="<td><a href=\"<c:url value='/resource/download/"+item.url+"'/>\">下载</a></td>";
		 s+="</tr>";
		 resourceList.append(s);
	 }
	 initPages(data.pageNo,data.allpages);
 }
 
 var initPages = function(pageNo,allpages){
		var classId = ${param.classId};
		var lastPageObj=$("#resourcePage .last-page");
		var nextPageObj=$("#resourcePage .next-page");
		var pageNumberObj=$("#resourcePage .page-number");
		var lastPage=pageNo-1;
		if(lastPage<=0){//设置disableed
			lastPage=1;
			lastPageObj.removeAttr("href");
		}else{//taskListStuView/taskPersonal
			lastPageObj.attr("href","<c:url value='/respository/listByClassId?classId="+classId+"&pageNo="+lastPage+"'/>");
		}
		var nextPage = pageNo+1;
		if(nextPage>allpages){
			nextPage=allpages;
			nextPageObj.removeAttr("href");
		}else{
			lastPageObj.attr("href","<c:url value='/respository/listByClassId?classId="+classId+"&pageNo="+nextPage+"'/>");
		}
		
		/* 需要进一步改进上下这块 */
		if(allpages <= 1){
			$("#resourcePage").hide();
		}else{
			pageNumberObj.text("第"+pageNo+"页/共"+allpages+"页");
			$("#resourcePage").show();
		}
	};
 </script>
</html>